package com.lvwenguo.controller;

import com.lvwenguo.model.ProductList;
import com.lvwenguo.service.ServiceInter;
import com.lvwenguo.service.serviceImple.ServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/SelectProductServlet/product/product_list")
public class SelectProductServlet extends HttpServlet {
    ServiceInter serviceImpol =new ServiceImple();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       String product_name=req.getParameter("product_name");
        //System.out.println(product_name);
        List<ProductList> lists = serviceImpol.selectProductList("%"+product_name+"%");
        if(lists.size()==0 || lists.get(0)==null){
            //System.out.println(lists);
            req.setAttribute("productList",lists);
            req.getRequestDispatcher("/view/product/product_list.jsp").forward(req,resp);
        }else{
            //System.out.println(lists);
            req.setAttribute("productList",lists);
            req.getRequestDispatcher("/view/product/product_list.jsp").forward(req,resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
